package com.jjc.android.fragment

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.IdRes
import com.bumptech.glide.Glide
import com.jjc.android.R
import com.jjc.android.activity.DetectionActivity
import com.jjc.android.activity.SamplingTakePhotoActivity
import com.jjc.android.base.BaseLazyLoadFragment
import com.jjc.android.view.onClick

class InsertCardFragment : BaseLazyLoadFragment() {

    companion object{
        fun newInstance():InsertCardFragment{
            val fragment = InsertCardFragment()
            fragment.setInflateLazy(true)
            return fragment
        }
    }

    override fun getLayoutId(): Int = R.layout.fragment_insert_card
    private val okBtn: TextView by lazy { findViewById(R.id.okBtn) }
    private val insertImageView:ImageView by lazy { findViewById(R.id.insertImageView) }

    override fun initView(view:View) {
        okBtn.onClick {
            (activity as? DetectionActivity)?.let {activity->
                SamplingTakePhotoActivity.start(activity,activity.getDetectionInfo()){
                    if(it){
                        activity.finish()
                    }
                }
            }
        }
        Glide
            .with(this)
            .asGif()
            .load(R.mipmap.insert_card_gif_icon_2)
            .into(insertImageView)
    }

    private fun <T : View?> findViewById(@IdRes id: Int): T {
        return rootView!!.findViewById<T>(id)
    }

}